package com.ctgu.springstart.dao;

import com.ctgu.springstart.domain.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserDao {

    /**
     * 根据用户名称，查询用户信息
     * @param username 用户名
     */
    @Select("select * from user where username = #{username}")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "username", column = "username"),
            @Result(property = "age", column = "age"),
            @Result(property = "phone", column = "phone"),
            @Result(property = "email", column = "email"),
    })
    User findByName(String username);

    @Select("select * from user where id = #{id}")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "username", column = "username"),
            @Result(property = "age", column = "age"),
            @Result(property = "phone", column = "phone"),
            @Result(property = "email", column = "email"),
    })
    User findById(Integer id);

    @Select("select * from user")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "username", column = "username"),
            @Result(property = "age", column = "age"),
            @Result(property = "phone", column = "phone"),
            @Result(property = "email", column = "email")
    })
    List<User> getAllUser();

    @Update("update user set username=#{username} where id=#{id}")
    void updateUser(User user);

    @Delete("delete from user where id =#{id}")
    void deleteUser(User user);
}
